package com.siwei.mes.entity.materials;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.config.UidUtils;
import com.siwei.mes.enums.GenerateCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
 * 物料表(Materials)实体类
 *
 * @author linzi
 * @since 2023-11-27 22:46:47
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_materials")
@ApiModel(value = "Materials", description = "物料表")
public class Materials implements Serializable {
    private static final long serialVersionUID = -54891438205001871L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "物料表主键ID", name = "id")
    private Long id;

    @Column(name = "material_no")
    @ApiModelProperty(value = "物料编号")
    private String materialNo;

    /**
     * 物料名称
     */
    @Column(name = "material_name")
    @ApiModelProperty(value = "物料名称", name = "materialName")
    private String materialName;

    /**
     * 物料规格
     */
    @Column(name = "material_specs")
    @ApiModelProperty(value = "物料规格", name = "materialSpecs")
    private String materialSpecs;
    /**
     * 物料类型  字典 MATERIAL_TYPE
     */
    @Column(name = "material_type")
    @ApiModelProperty(value = "物料类型  字典 MATERIAL_TYPE", name = "materialType")
    private Integer materialType;
    /**
     * 物料类型 字典名称
     */
    @Column(name = "material_type_name")
    @ApiModelProperty(value = "物料类型 字典名称", name = "materialTypeName")
    private String materialTypeName;

    @Column(name = "spec_id")
    @ApiModelProperty(value = "规格id  pk_materials_spec_config 表的id")
    private Long specId;


    @Column(name = "is_iron_mark")
    @ApiModelProperty(value = "是否铁标  0-否 1-是")
    private Integer isIronMark;

    @Column(name = "phb_no")
    @ApiModelProperty(value = "配合比编号")
    private String phbNo;

    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    /**
     * 配置的材料类型
     */
    @Transient
    @ApiModelProperty(value = "配置的材料类型", name = "materialsType")
    private Integer materialsConfigType;
    /**
     * 配置的材料名称
     */
    @Transient
    @ApiModelProperty(value = "配置的材料名称", name = "materialsName")
    private String materialsConfigName;
    /**
     * 配置的材料规格
     */
    @Transient
    @ApiModelProperty(value = "配置的材料规格", name = "materialsSpec")
    private String materialsConfigSpec;

    /**
     * 配置的材料简称
     */
    @Transient
    @ApiModelProperty(value = "配置的材料简称")
    private String materialAbbreviation;

    @Transient
    @ApiModelProperty(value = "多个类型")
    private List<Long> materialsTypeList;

    @Transient
    @ApiModelProperty(value = "指标类型 0-所有 1-未设置 2-已设置")
    private Integer isConfig;

    @Transient
    @ApiModelProperty(value = "协会试验依据")
    private String sampleJudge;

    public Materials init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date())
                    .setIsDel(0).setMaterialNo(UidUtils.genNo(GenerateCodeEnum.MATERIALS.getCode()));
        }
        return this;
    }
}
